package com.bysc.executor.handler;

import com.bysc.baseservice.config.RabbitmqConfig;
import com.bysc.baseservice.handler.BaiYunException;
import com.bysc.commonutils.Results;
import com.bysc.commonutils.constant.RedisConstant;
import com.bysc.commonutils.vo.JoinForm;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.List;
import java.util.concurrent.TimeUnit;

import static com.bysc.commonutils.constant.RedisConstant.JOIN_FORM;

@Component
public class ScoreJobHandler {

    @Autowired
    private RabbitTemplate rabbitTemplate;
    /**
     * 学习资料定时计算分数
     */
    @XxlJob("StudyScoreJob")
    public void StudyScoreJob() throws Exception {
        try {
            System.out.println("StudyScoreJob执行了.... " + LocalDateTime.now());
            rabbitTemplate.convertAndSend(RabbitmqConfig.EXCHANGE_STUDY_SCORE, RabbitmqConfig.ROUTING_STUDY_SCORE, "111");
            System.out.println("StudyScoreJob执行结束了.... " + LocalDateTime.now());
        } catch (Exception e) {
            e.printStackTrace();
            throw new BaiYunException(20001, "学习资料定时计算分数错误");
        }
    }
    /**
     * 帖子分数定时计算
     */
    @XxlJob("PostScoreJob")
    public void PostScoreJob() throws Exception {
        try {
            System.out.println("PostScoreJob执行了.... " + LocalDateTime.now());
            rabbitTemplate.convertAndSend(RabbitmqConfig.EXCHANGE_POST_SCORE, RabbitmqConfig.ROUTING_POST_SCORE, "111");
            System.out.println("PostScoreJob执行结束了.... " + LocalDateTime.now());
        } catch (Exception e) {
            e.printStackTrace();
            throw new BaiYunException(20001, "帖子分数定时计算错误");
        }
    }

}
